package com.cat.model.web.action.admin.order;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alonew.core.commons.page.Page;
import com.cat.model.common.enumerator.SubjectType;
import com.cat.model.common.model.common.BasOrderVO;
import com.cat.model.dao.common.PlmCommDAO;
import com.cat.model.dao.mapper.ModelMapper;
import com.cat.model.web.action.base.AdminAction;

public class DressupOrderManagerAction extends AdminAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 425636316597986569L;
	
	private Long id;
	private String orderNumber;
	private Integer status;
	private String subjectName;
	private Date createBeginTime;
	private Date createEndTime;
		
	@Autowired
	private PlmCommDAO plmCommDAO;
	
	@Autowired
	private ModelMapper modelMapper;
	
	/**
	 * list
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String list() {
		Map<String, Object> condition = new HashMap<String, Object>();
		
		if(StringUtils.isNotEmpty(orderNumber)){
			condition.put("orderNumber", orderNumber);
		}
		
		if(status!=null){
			condition.put("status", status);
		}
		
		if(StringUtils.isNotEmpty(subjectName)){
			condition.put("subjectName", subjectName);
		}
		
		if(createBeginTime!=null){
			condition.put("createBeginTime", createBeginTime);
		}
		
		if(createEndTime!=null){
			condition.put("createEndTime", createEndTime);
		}
		
		condition.put("subjectType", SubjectType.Dressup.getValue());
		
		Page page = this.fetchPageParams();
		page.setNumPerPage(20);
		
		Long totalCount = plmCommDAO.searchSize("manager.searchBasOrderSize", condition);
		page.setTotalCount(totalCount);
		int start = (page.getPageNum() -1) * page.getNumPerPage();
		if(start < 0){
			start = 0;
		}
		
		List<BasOrderVO> list = (List<BasOrderVO>)plmCommDAO.search("manager.searchBasOrder", condition, start, page.getNumPerPage());
		
		request.setAttribute("list", list);
		request.setAttribute("size", totalCount);
		return "list";
	}
	
	public String detail(){
		BasOrderVO order = modelMapper.getBasOrderByOrderNumber(orderNumber);
		request.setAttribute("item", order);
		
		return "detail";
	}
	
	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public String getOrderNumber() {
		return orderNumber;
	}


	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}


	public Integer getStatus() {
		return status;
	}


	public void setStatus(Integer status) {
		this.status = status;
	}


	public String getSubjectName() {
		return subjectName;
	}


	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	}


	public Date getCreateBeginTime() {
		return createBeginTime;
	}


	public void setCreateBeginTime(Date createBeginTime) {
		this.createBeginTime = createBeginTime;
	}


	public Date getCreateEndTime() {
		return createEndTime;
	}


	public void setCreateEndTime(Date createEndTime) {
		this.createEndTime = createEndTime;
	}


}
